unit fEmployeeRegisterInfo;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, fEmbedTlbLayout, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinCaramel, dxSkinOffice2010Silver,
  dxSkinSeven, dxSkinscxPCPainter, cxStyles, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, dxLayoutControl,
  dxSkinsdxStatusBarPainter, dxSkinsdxBarPainter, cxContainer, uDAInterfaces,
  uDADataTable, uDAScriptingProvider, uDAMemDataTable, dxBar, cxClasses,
  dxStatusBar, frAttachs, ExtCtrls, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridBandedTableView, cxGridDBBandedTableView,
  cxGridCustomView, cxGrid, cxPC, StdCtrls, RzLabel, RzDBLbl, dImages, RzDBEdit,
  Mask, RzEdit, dxLayoutControlAdapters, RzCmboBx, RzDBCmbo, DBCtrls,
  cxPCdxBarPopupMenu, cxNavigator, dxLayoutContainer, RzShellDialogs, Menus;

type
  TfmEmployeeRegisterInfo = class(TfmEmbedTlbLayout)
    RzDBEdit1: TRzDBEdit;
    lcMainItem1: TdxLayoutItem;
    RzDBEdit2: TRzDBEdit;
    lcMainItem2: TdxLayoutItem;
    RzDBDateTimeEdit1: TRzDBDateTimeEdit;
    lcMainItem3: TdxLayoutItem;
    RzDBDateTimeEdit2: TRzDBDateTimeEdit;
    lcMainItem4: TdxLayoutItem;
    RzDBMemo1: TRzDBMemo;
    lcMainItem5: TdxLayoutItem;
    RzDBMemo2: TRzDBMemo;
    lcMainItem6: TdxLayoutItem;
    cbxStaff: TRzDBComboBox;
    lcMainItem7: TdxLayoutItem;
    cbxRegisterType: TRzDBComboBox;
    lcMainItem10: TdxLayoutItem;
    RzDBDateTimeEdit3: TRzDBDateTimeEdit;
    lcMainItem11: TdxLayoutItem;
    RzDBDateTimeEdit4: TRzDBDateTimeEdit;
    lcMainItem12: TdxLayoutItem;
    procedure cbxStaffDropDown(Sender: TObject);
    procedure cbxStaffChange(Sender: TObject);
    procedure cbxRegisterTypeDropDown(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure tblBaseNewRecord(DataTable: TDADataTable);
    procedure bbtnSaveClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Initialize(AId: TGuid); overload; override;
    procedure CheckNotNullFields; override;
  end;

var
  fmEmployeeRegisterInfo: TfmEmployeeRegisterInfo;

implementation

uses
  tools;

{$R *.dfm}

procedure TfmEmployeeRegisterInfo.CheckNotNullFields;
begin

end;

procedure TfmEmployeeRegisterInfo.Initialize(AId: TGUID);
begin
  FId := AId;
  InitDataSets;
  inherited Initialize;
end;

procedure TfmEmployeeRegisterInfo.tblBaseNewRecord(DataTable: TDADataTable);
var
  value: array of Variant;
begin
  inherited;
  tblBase.FieldByName('der_staff').AsString := GetUserName;
  SetLength(value, 4);
  if GetSelectedValue('select bu_depart,bu_id,bu_cname,bu_iid from b_user where bu_name='+ QuotedStr(GetUserName), value) then
  begin
    tblBase.FieldByName('der_department').Value := value[0];
    tblBase.FieldByName('der_staffid').Value := value[1];
    tblBase.FieldByName('der_employee').Value := value[2];
    tblBase.FieldByName('der_staffiid').Value := value[3];    
  end;

  tblBase.FieldByName('der_datestart').AsDateTime := Now;
  tblBase.FieldByName('der_dateend').AsDateTime := Now;
  tblBase.FieldByName('der_datestart2').AsDateTime := Time;
  tblBase.FieldByName('der_dateend2').AsDateTime := Time;

end;

procedure TfmEmployeeRegisterInfo.bbtnSaveClick(Sender: TObject);
begin

//

  inherited;

end;

procedure TfmEmployeeRegisterInfo.cbxRegisterTypeDropDown(Sender: TObject);
begin
  inherited;
  SetRzComboxPopup('select bcrt_name from b_c_registertype', cbxRegisterType);
end;

procedure TfmEmployeeRegisterInfo.cbxStaffChange(Sender: TObject);
var
  value: array of Variant;
begin
  if FDatasetOpenning then Exit;
  if not (tblBase.State in [dsInsert, dsEdit]) then Exit;
  SetLength(value, 4);
  if GetSelectedValue('select bu_depart,bu_id,bu_cname,bu_iid from b_user where bu_name='+ QuotedStr(GetUserName), value) then
  begin
    tblBase.FieldByName('der_department').Value := value[0];
    tblBase.FieldByName('der_staffid').Value := value[1];
    tblBase.FieldByName('der_employee').Value := value[2];
    tblBase.FieldByName('der_staffiid').Value := value[3];    
  end;
end;

procedure TfmEmployeeRegisterInfo.cbxStaffDropDown(Sender: TObject);
begin
  inherited;
  SetRzComboxPopup('select bu_name from b_user', cbxStaff);
end;

procedure TfmEmployeeRegisterInfo.FormCreate(Sender: TObject);
begin
  FModal := 'EmployeeRegister';
  FHasDetails := False;
  FIdField := 'der_id';

  FCreateDateField := 'der_createdate';
  FCreateStaffField := 'der_createstaff';
  FModifyDateField := 'der_modifydate';
  FModifyStaffField := 'der_modifystaff';
  FWidthAdjust := -28;
  inherited;

end;

end.
